package com.xasz.text2vec.utils;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.*;
import java.util.*;

public class IKUtil {
    /**
     * 分词细分
     * @param keyword
     * @return
     * @throws IOException
     */
    public static List<String> splitKeyWord(String keyword) throws IOException {

        ArrayList<String> result = new ArrayList<>();
        // 创建一个reader对象
        StringReader reader = new StringReader(keyword);
        // 创建一个分词对象
        IKSegmenter ikSegmenter = new IKSegmenter(reader, false);
        Lexeme next = ikSegmenter.next();

        while ( next != null ) {
            // 获取分词的结果
            result.add(next.getLexemeText());
            next = ikSegmenter.next();
        }
        return result;
    }
}
